package com.gps.misc;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;

import com.appengine.utils.GsonUtils;
import com.appengine.utils.SavingAndLoadingCenter;
import com.appengine.utils.UserUtils;
import com.datatypes.Friend;
import com.datatypes.FriendsZone;
import com.datatypes.Track;
import com.datatypes.User;
import com.datatypes.listItemData;
import com.gps.track.GpsTrackingActivitySolo;
import com.sporteamws.R;
import com.sporteamws.SharedPref;

public class FriendsCenter extends Activity implements OnItemClickListener,
		OnCreateContextMenuListener {

	ArrayList<listItemData> listVals = null;
	User user = null;
	FriendsZone fz = null;
	String title = "";
	int position = 0;
	EditText newName = null;
	private ListView list;
	private ActivityList adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list);
		newName = new EditText(this);
		listVals = new ArrayList<listItemData>();
		String UserStr = getIntent().getExtras().getString("USER");

		user = GsonUtils.ConvertGsonStringToUser(UserStr);
		fz = SavingAndLoadingCenter.loadFriendsZone(user.GetFacebookID(), this);
		
		for (Friend f : fz.getFriends()) {
			if (!f.isInActivity())
				listVals.add(new listItemData(f));
		}

		list = (ListView) findViewById(R.id.list);
		list.setSelector(R.layout.list_selector_friend);
		adapter = new ActivityList(this, listVals); 
		list.setAdapter(adapter);
		list.setOnItemClickListener(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	public void onItemClick(AdapterView<?> l, View v, int position, long id) {
		String friendFB_ID = listVals.get(position).getFriend().getFbID();
		Intent intent = new Intent(this, GpsTrackingActivitySolo.class);
		Bundle bundle = new Bundle();
		bundle.putString("FRIEND", friendFB_ID);
		bundle.putString("USER", getIntent().getExtras().getString("USER"));
		bundle.putBoolean("SOLO", false);
		intent.putExtras(bundle);
		
		startActivity(intent);

	}
}
